package com.radar.io.radar346.DataType;

import com.radar.common.GisConstants;
import com.radar.io.radar346.Product382改;
import com.radar.utils.BitConverter;

public class LRMParse {
    Product382改 _this;
    float 窗口宽度;
    int 计算分层组合反射率最大值的窗口个数;
    float 第一层高度;
    float 第二层高度;
    float 第三层高度;
    float 第一层最大值;
    float 第二层最大值;
    float 第三层最大值;

    public LRMParse(Product382改 product382改) {
        _this = product382改;
    }

    public void parse(byte[] bytes, int index, Product382改.RealFile header) throws Exception {
        int Layers = header.realObserSec.iLiTiSaoMiaoCengShu;
        int[] Records = new int[Layers];
        double[] MaxV = new double[Layers];
        int Bins = 0;
        for (int i = 0; i < Layers; i++) {
            Records[i] = header.realObserSec.LayerParam[i].iCaiYangJinXiangShu;
            Bins = header.realObserSec.LayerParam[i].usRefBinNumber;
        }
        _this.azi = new double[Records[0]];  //长度为每层径向数

        float 窗口宽度 = BitConverter.toFloat(bytes, index);
        this.窗口宽度 =窗口宽度;
        index+=4 ;
        Float 计算分层组合反射率最大值的窗口个数 = BitConverter.toFloat(bytes, index);
        this.计算分层组合反射率最大值的窗口个数 =计算分层组合反射率最大值的窗口个数.intValue();
        index += 4 ;
        float 第一层高度 = BitConverter.toFloat(bytes, index);
        this.第一层高度 =第一层高度;
        index += 4 ;
        float 第二层高度 = BitConverter.toFloat(bytes, index);
        this.第二层高度 =第二层高度;
        index += 4 ;
        float 第三层高度 = BitConverter.toFloat(bytes, index);
        this.第三层高度 =第三层高度;
        index += 4 ;
        float 第一层最大值 = BitConverter.toFloat(bytes, index);
        this.第一层最大值 =第一层最大值;
        index += 4 ;
        float 第二层最大值 = BitConverter.toFloat(bytes, index);
        this.第二层最大值 =第二层最大值;
        index += 4 ;
        float 第三层最大值 = BitConverter.toFloat(bytes, index);
        this.第三层最大值 =第三层最大值;
        index += 4 ;
        int forEachNum = 计算分层组合反射率最大值的窗口个数.intValue();
        _this.data3d = new double[3][(int) (forEachNum * 窗口宽度)][(int) (forEachNum * 窗口宽度)];
        for (int z = 0; z < 3; z++) {
            float[][] x1 = new float[forEachNum][forEachNum];
            float[][] x2 = new float[forEachNum][forEachNum];
            float[][] x3 = new float[forEachNum][forEachNum];
            float[][] x4 = new float[forEachNum][forEachNum];

            if (z==0){
                for (int ii = 0; ii < forEachNum; ii++) {
                    for (int jj = 0; jj < forEachNum; jj++) {
                        x1[ii][jj] = BitConverter.toSingle(bytes, index);
                        x2[ii][jj] = BitConverter.toSingle(bytes, index + forEachNum * forEachNum * 4);
                        x3[ii][jj] = BitConverter.toSingle(bytes, index + forEachNum * forEachNum * 4 * 2);
                        x4[ii][jj] = BitConverter.toSingle(bytes, index + forEachNum * forEachNum * 4 * 3);
                        index += 4;
                    }
                }
            }
            if (z==1||z==2){
                index+=forEachNum*forEachNum*3*4;
                for (int ii = 0; ii < forEachNum; ii++) {
                    for (int jj = 0; jj < forEachNum; jj++) {
                        x1[ii][jj] = BitConverter.toSingle(bytes, index);
                        x2[ii][jj] = BitConverter.toSingle(bytes, index + forEachNum * forEachNum * 4);
                        x3[ii][jj] = BitConverter.toSingle(bytes, index + forEachNum * forEachNum * 4 * 2);
                        x4[ii][jj] = BitConverter.toSingle(bytes, index + forEachNum * forEachNum * 4 * 3);
                        index += 4;
                    }
                }
            }
            for (int ii = 0; ii < forEachNum; ii++) {
                for (int jj = 0; jj < forEachNum; jj++) {
                    _this.data3d[z][ii][jj] = x2[forEachNum - 1 - ii][forEachNum - 1 - jj];
                    _this.data3d[z][ii + forEachNum][jj] = x3[ii][forEachNum - 1 - jj];
                    _this.data3d[z][ii + forEachNum][jj + forEachNum] = x4[ii][jj];
                    _this.data3d[z][ii][jj + forEachNum] = x1[forEachNum - 1 - ii][jj];
                }
            }
        }
    }
}
